using System.Web.UI;
namespace BLL.Classes
{
    public class CategoryData : IHierarchyData
    {
        private Category _category;

        public CategoryData(Category category)
        {
            this._category = category;
        }

        public IHierarchicalEnumerable GetChildren()
        {
            return new CategoryCollection(this._category.SubCategories);
        }

        public IHierarchyData GetParent()
        {
            return new CategoryData(this._category.Parent);
        }

        public bool HasChildren
        {
            get
            {
                if (this._category.SubCategories == null)
                    return false;
                return (this._category.SubCategories.Count > 0);
            }
        }

        public object Item
        {
            get { return _category; }
        }

        public string Path
        {
            get
            {
                Category section = this._category;
                string s = this._category.Title;
                while ((_category = _category.Parent) != null)
                    s = _category.Title + ": " + s;
                return s.Trim();
            }
        }
        public string Type
        {
            get { return this._category.ToString(); }
        }
    }

}
